package com.ybfenpan.controller.admin.member;

import com.ybfenpan.model.Daili;
import com.ybfenpan.model.Member;
import com.ybfenpan.response.Resp;
import com.ybfenpan.service.DailiService;
import com.ybfenpan.service.MemberService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lzx on 2017/6/1.
 */
@Controller
public class TuCommonLineController {

    @Resource
    private MemberService memberService;

    @Resource
    private DailiService dailiService;

    @GetMapping("/admin/member/tuCommonLine.shtml")
    public String toCommonLine() {

        return "admin/member/tuCommonLine";
    }

    @RequestMapping("/admin/member/commonLine.shtml")
    @ResponseBody
    public Resp commonLineList(String loginName, Integer level, Integer dailiId) {

        Member member = memberService.executMemberByLoginName(loginName);
        if (member != null) {
            level = member.getLevel();
            dailiId = member.getDailiId();
        } else {
            if (level == null) {
                level = 1;
            }
        }

        Daili daili = dailiService.getByKey(dailiId);
        if (daili == null) {
            return new Resp(-1,"该代理商等级不存在");
        }

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("where", " dailiId = " + dailiId + " and level >= " + level + " order by level limit 10");
        List list = memberService.queryForList("select", paramMap);

        Resp resp = new Resp();
        resp.data = list;
        return resp;
    }


}
